/**
 * 封装axios文件
 */
import axios from 'axios'

const instance = axios.create({
    // 全局配置项
    baseURL: 'http://localhost:3001/',
    timeout: 5000
})

// 请求拦截
instance.interceptors.request.use(config => {
    if(localStorage.getItem('token')){
        // const token = JSON.parse(localStorage.getItem('token')).token
        // console.log(token)
        // config.headers.token = token
        // config.headers['Authorization'] = `Bearer ${token}`
        config.headers['X-Nideshop-Token'] = localStorage.getItem('token')
    }
    return config
},err => {
    return new Promise.reject(err)
})

// 响应拦截:
instance.interceptors.response.use(res => {
    return res
},err => {
    return new Promise.reject(err)
})

export default instance